# 添加数据

"""
1.创建会话
"""
from sqlalchemy.orm import sessionmaker
from create_table_foreignkey import engine
Session = sessionmaker(engine)
db_session = Session()

# 2.导入学校 学生
from create_table_foreignkey import School, Student


# 3. 添加数据
"""
# 2.添加数据  - 正向  relationship
"""
studen_obj = Student(name="Any",stu2sch=School(name="清华"))
db_session.add(studen_obj)
db_session.commit()
db_session.close()


"""
# 1. 添加数据 - 反向 relationship
"""
school_obj = School(name="北大")  # 创建学校
school_obj.sch2stu = [Student(name="Jack"),Student(name="Jeecy")]  # 学校关联学生
db_session.add(school_obj)
db_session.commit()
db_session.close()


